package com.class05.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/21 15:20
 */
@Configuration
@PropertySource("classpath:jdbc.properties")
public class DataSourceJavaConfig {
    @Value("${class05.username}")
    private String username;
    @Value("${class05.password}")
    private String password;
    @Value("${class05.driver}")
    private String driver;
    @Value("${class05.url}")
    private String url;
    @Bean
    public DataSource dataSource(){
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setUsername(username);
        dataSource.setJdbcUrl(url);
        dataSource.setDriverClassName(driver);
        dataSource.setPassword(password);
        return dataSource;
    }
}
